<template>
  <div v-drag>
    <div class="mask"  @click="closePopup(false)"></div>
    <div class="edit_box" v-loading="loading">
      <div class="box_head">
        <p>分配订单</p>
        <i  @click="closePopup(false)"></i>
      </div>
      <div class="box_body" >
        <div class="line" :class="{'error_border':tip_num===0}">
          <span class="lab"><i class="mark_icon">*</i>配送员：</span>
          <div>
            <el-select
              v-model="sender"
              filterable
              placeholder="请选择配送员">
              <el-option
                v-for="(item,index) in senderOption"
                :key="index"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </div>
        </div>
        <p class="error_line">{{infoTip}}</p>
      </div>
      <div class="box_foot">
        <span @click="closePopup(false)">取消</span>
        <span @click="confirmEdit">确定</span>
      </div>
    </div>
  </div>
</template>

<script>
import { assignOrder } from "@/api/data/user/productSend";
import {getAllData} from "@/api/basic/warehouse/sender";

export default {
  props:['recordId','warehouseId'],
  data(){
    return {
      sender: '',
      senderOption: '',
      infoTip: '',
      tip_num: '',
      loading:false
    }
  },
  mounted() {
    this.getSender();
  },
  methods:{
    getSender(){
      let param = {
        warehouseId: this.warehouseId,
        isAll:1
      };
      getAllData(param).then(res => {
        this.senderOption = res?res:[];
      }).catch((e) => {
        this.senderOption = [];
      });
    },

    // 确认编辑
    confirmEdit(){
      if (this.sender === '') {
        this.setTip(1, '请选择配送员！');
      } else {
        this.sendInfo();
      }
    },

    sendInfo(){
      let that = this;
      that.loading = true;
      let data = {
        recordId: that.recordId,
        senderId: that.sender,
      }
      assignOrder(data).then(response => {
        that.closePopup(true);
        that.$message.success({
          message:'操作成功！',
          duration:1500
        });
        that.loading = false;
      }).catch((e) => {
        that.loading = false;
      });
    },

    setTip(num,text){
      this.tip_num = num;
      this.infoTip = text
    },

    // 关闭
    closePopup(refresh){
      this.$emit('listenToChild', {refresh: refresh})
    }
  }
}
</script>

<style scoped>


</style>

